package org.coding.springbootdemowebmvc.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @auth guoxh
 * @date 2020/10/17 3:29 下午
 * @desc
 **/
@Component
public class AnnotationScannerConfigurer implements ApplicationContextAware, BeanDefinitionRegistryPostProcessor {
    private final static Logger logger = LoggerFactory.getLogger(AnnotationScannerConfigurer.class);
    private ApplicationContext applicationContext;
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry beanDefinitionRegistry) throws BeansException {
        logger.info("postProcessBeanDefinitionRegistry() beandefinitionName: {}",beanDefinitionRegistry.getBeanDefinitionNames().toString());
//        CodeRuleAnnotationScanner scanner = new CodeRuleAnnotationScanner(beanDefinitionRegistry);
//
//        scanner.setResourceLoader(applicationContext);
//        scanner.scan("org.coding");

        UserServiceAnnotationScanner scanner1 = new UserServiceAnnotationScanner(beanDefinitionRegistry);
        scanner1.setResourceLoader(applicationContext);
        scanner1.scan("org.coding");
    }

    public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
        logger.info("postProcessBeanFactory() beandefinition的个数:{}",configurableListableBeanFactory.getBeanDefinitionCount());
    }

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}
